package com.kosmos.dubhe.wxcp.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wukai
 */
@Slf4j
public abstract class AbstractWebConfig implements WebMvcConfigurer {
    @Value("${characterEncoding:UTF-8}")
    protected String characterEncoding;


    @Value("${allow.cross.domain:*}")
    private String allowDomain;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/rest/**")
                .allowedOrigins("*")//放行哪些原始域-生产环境中时，照此设置"http://domain2.com"
                .allowedMethods("*")//放行哪些原始域(请求方式)"GET","POST", "PUT", "DELETE"
                .allowedHeaders("*")//"header1", "header2", "header3"
                .exposedHeaders("access-control-allow-headers",
                        "access-control-allow-methods",
                        "access-control-allow-origin",
                        "access-control-max-age",
                        "X-Frame-Options")
                .allowCredentials(true).maxAge(3600);//是否发送Cookie信息，maxAge 以秒为单位
    }
}
